
package com.thxrinfo.stop.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.thxrinfo.stop.api.entity.LotDevice;
import com.thxrinfo.stop.api.entity.RegionLotRoad;
import com.thxrinfo.stop.api.vo.LotDeviceVO;
import com.thxrinfo.stop.mapper.LotDeviceMapper;
import com.thxrinfo.stop.service.LotDeviceService;
import com.thxrinfo.stop.service.RegionLotRoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 路边车场地磁设备
 *
 * @author ct
 * @date 2023-02-10 11:41:34
 */
@Service
public class LotDeviceServiceImpl extends ServiceImpl<LotDeviceMapper, LotDevice> implements LotDeviceService {

	@Autowired
	private RegionLotRoadService regionLotRoadService;
	@Override
	public IPage<LotDevice> page(Page page, LotDevice lotDevice) {
		return baseMapper.page(page, lotDevice);
	}

	@Override
	public boolean updateBoundStatus(LotDevice lotDevice) {
		//通过是否传入lotId判断操作为绑定还是解绑
		Long lotId = lotDevice.getLotId();
		RegionLotRoad regionLotRoad = new RegionLotRoad();
		regionLotRoad.setHardwareSn(lotDevice.getSn());
		if (lotId != null) {
			//修改路边车场车位表
			regionLotRoad.setId(lotId);
			lotDevice.setType(1);
			regionLotRoadService.updateById(regionLotRoad);
		} else {
			regionLotRoadService.updateHardwareSn(regionLotRoad);
			return baseMapper.unBound(lotDevice.getId());
		}
		return updateById(lotDevice);
	}

	@Override
	public LotDeviceVO getById(Long id) {
		return baseMapper.getById(id);
	}
}
